package com.spzx.order.configure;

import com.spzx.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class CancelOrderMqConfig {

    @Bean
    public Queue queue(){
        return new Queue(MqConst.QUEUE_CANCEL_ORDER);
    }

    @Bean
    public CustomExchange customExchange(){
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-delayed-type","direct");
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER,"x-delayed-message",true,false,args);
    }

    public Binding binding(){
        return BindingBuilder.bind(queue()).to(customExchange()).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
    }
}
